package logic

import (
	"context"

	"mail/service/outlay/api/internal/svc"
	"mail/service/outlay/api/internal/types"
	"mail/service/outlay/rpc/outlayclient"

	"github.com/zeromicro/go-zero/core/logx"
)

type WritLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewWritLogic(ctx context.Context, svcCtx *svc.ServiceContext) *WritLogic {
	return &WritLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *WritLogic) Writ(req *types.WritRequest) (resp *types.WritResponse, err error) {
	// todo: add your logic here and delete this line
	thoughtful, err := l.svcCtx.OutlayRpc.Writ(l.ctx, &outlayclient.WritRequest{
		Id: req.Id,
	})
	if err != nil {
		return nil, err
	}
	return &types.WritResponse{
		Id:     thoughtful.Id,
		Uid:    thoughtful.Uid,
		Rid:    thoughtful.Rid,
		Amount: thoughtful.Amount,
		Source: thoughtful.Source,
		Status: thoughtful.Status,
	}, nil
}
